home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTDRIVER / STRING.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  1.6 KB  |  115 lines

  1. /* string.c */
  2.  
  3. /*
  4.  *    string -- handy string functions
  5.  *
  6.  *----
  7.  * <sometime> JWTittsler    Original stuff.
  8.  * 13-Mar-1986 lmd        Some more functions.
  9.  */
  10.  
  11.  
  12. /*
  13.  * Cat string2 onto string1
  14.  *
  15.  */
  16. char *strcat(s1, s2)
  17. register char *s1;
  18. register char *s2;
  19. {
  20.     char *sptr;
  21.  
  22.     sptr = s1;
  23.     while (*s1++)        /* find the end of s1 */
  24.         ;
  25.     --s1;            /* back up so we point to the null */
  26.     while (*s1++ = *s2++)    /* tack on s2 */
  27.         ;
  28.     return sptr;
  29. }
  30.  
  31.  
  32. /*
  33.  * Copy string2 to string1
  34.  *
  35.  */
  36. char *strcpy(s1, s2)
  37. register char *s1;
  38. register char *s2;
  39. {
  40.     char *sptr;
  41.  
  42.     sptr = s1;
  43.     while (*s1++ = *s2++)
  44.     ;
  45.     return sptr;
  46. }
  47.  
  48.  
  49. /*
  50.  * Replace occurances of `c1' in the string `s'
  51.  * with `c2'.
  52.  *
  53.  */
  54. char *strrep(s, c1, c2)
  55. register char *s;
  56. register char c1;
  57. register char c2;
  58. {
  59.     char *sptr;
  60.  
  61.     sptr = s;
  62.     while (*s)
  63.     if(*s == c1)
  64.         *s++ = c2;
  65.         else ++s;;
  66.  
  67.     return sptr;
  68. }
  69.  
  70.  
  71. /*
  72.  * Return uppercase of `c'
  73.  *
  74.  */
  75. char toupper(c)
  76. char c;
  77. {
  78.     if(c >= 'a' && c <= 'z')
  79.     c -= 0x20;
  80.     return c;
  81. }
  82.  
  83.  
  84. /*
  85.  * Return `1' if `c' is an ascii space, tab, or newline.
  86.  *
  87.  */
  88. isspace(c)
  89. char c;
  90. {
  91.     if(c == 0x20 ||
  92.        c == '\t' ||
  93.        c == '\n') return 1;
  94.  
  95.     return 0;
  96. }
  97.  
  98.  
  99. /*
  100.  * Return `0' if the strings match, `1' if they don't;
  101.  * uppercase letters match their lowercase counterparts.
  102.  *
  103.  */
  104. strcmp(st1, st2)
  105. char *st1, *st2;
  106. {
  107.     register char *s1, *s2;
  108.  
  109.     s1 = st1;
  110.     s2 = st2;
  111.     while(*s1 && toupper(*s1) == toupper(*s2))
  112.     ++s1, ++s2;
  113.     return (*s1 != *s2);
  114. }
  115.